import { id } from "element-plus/es/locale"

export const menuData = [
    {
        id: "1",
        label: "首页",
        path: "/Home/AdminIndex"
    },
    {
        id: "2",
        label: "轮播图管理",
        children: [
            {
                id: "2-1",
                label: "轮播图列表",
                path: "/Home/BannerList",
                children: [
                    {
                        id: "2-1-R",
                        label: "读取轮播图数据",
                    },
                    {
                        id: "2-1-U",
                        label: "修改轮播图状态",
                    }
                ]
            },
            {
                id: "2-2",
                label: "轮播图添加",
                path: "/Home/BannerAdd"
            },
            {
                id: "2-3",
                label: "轮播图删除",
                path: "/Home/BannerDel",
                children: [
                    {
                        id: "2-3-R",
                        label: "删除轮播图数据读取",
                    },
                    {
                        id: "2-3-D",
                        label: "删除轮播图数据",
                    }
                ]
            }
        ]
    },
    {
        id: "3",
        label: "操作人员管理",
        children: [
            {
                id: "3-1",
                label: "操作人员列表",
                path: "/Home/AdminList",
                children: [
                    {
                        id: "3-1-R",
                        label: "操作人员列表读取"
                    },
                    {
                        id: "3-1-D",
                        label: "操作人员删除"
                    },
                    {
                        id: "3-1-U",
                        label: "操作人员修改"
                    },
                ]
            },
            {
                id: "3-2",
                label: "操作人员添加",
                path: "/Home/AdminAdd"
            }
        ]
    },
    {
        id: "4",
        label: "商品",
        children: [
            {
                id: "4-1",
                label: "商品分类搜索",
                path: "/Home/GoodCategory"
            },
            {
                id: "4-2",
                label: "商品分页",
                path: "/Home/GoodPage"
            },
            {
                id: "4-3",
                label: "秒杀和推荐列表",
                path: "/Home/GoodSeckillOrRecommend"
            },
        ]
    },
    {
        id: "5",
        label: "搜索",
        children: [
            {
                id: "5-1",
                label: "搜索关键词列表",
                path: "/Home/SearchKeywords"
            }
        ]
    },
    {
        id: "6",
        label: "用户数据",
        children: [
            {
                id: "6-1",
                label: "查看用户数据",
                path: "/Home/User"
            },
            {
                id: "6-2",
                label: "用户地址信息",
                path: "/Home/AddressList"
            },
        ]
    },
    {
        id: "7",
        label: "订单数据",
        children: [
            {
                id: "7-1",
                label: "查看订单数据",
                path: "/Home/OrderList",
                children: [
                    {
                        id: "7-1-R",
                        label: "读取订单数据"
                    },
                    {
                        id: "7-1-U",
                        label: "修改订单状态"
                    },
                ]
            },
            {
                id: "7-2",
                label: "查看订单状态",
                path: "/Home/LookStatusOrder"
            }
        ]
    },
    {
        id: "8",
        label: "购物车管理",
        children: [
            {
                id: "8-1",
                label: "购物车列表",
                path: "/Home/CartList"
            },
        ]
    },
    {
        id: "9",
        label: "图表数据",
        children: [
            {
                id: "9-1",
                label: "K线图",
                path: "/Home/LinearKChart"
            },
            {
                id: "9-2",
                label: "简单图表数据",
                path: "/Home/SimpleChart"
            }
        ]
    },
]

export default function getGrants() {
    let ckeckedkeys: string[] = []
    let currentkeys = sessionStorage.getItem("grants")
    if (currentkeys) {
        ckeckedkeys = JSON.parse(currentkeys)
    }


    if (ckeckedkeys.length === 0) {
        ckeckedkeys = ["1", "2", "2-1", "2-1-R", "2-1-U", "2-2", "2-3", "2-3-D", "3", "3-1", "3-2", "4", "4-1", "4-2", "4-3", "5", "5-1", "6", "6-1", "6-2", "7", "7-1", "7-2", "8", "8-1", "9", "9-1", "9-2"]
    }


    interface IMenuItem {
        id: string,
        label: string,
        path?: string,
        children?: IMenuItem[]
    }
    let currMenuData: IMenuItem[] = []
    menuData.forEach(item => {
        if (ckeckedkeys.indexOf(item.id) > -1) {
            currMenuData.push({ ...item })
            if (item.children) {
                currMenuData[currMenuData.length - 1].children = []
                item.children.forEach(sonItem => {
                    if (ckeckedkeys.indexOf(sonItem.id) > -1) {
                        currMenuData[currMenuData.length - 1].children?.push({ ...sonItem })
                    }
                })
            }
        }
    })
    return currMenuData
}